package cn.net.xyan.easy.gwt.client.ui;


import cn.net.xyan.easy.gwt.client.event.ActionEvent;
import cn.net.xyan.easy.gwt.client.event.ActionEventBus;
import cn.net.xyan.easy.gwt.client.model.MenuItemModel;
import com.google.gwt.dom.client.Style;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import org.gwtbootstrap3.client.ui.AnchorListItem;


/**
 * Created by zarra on 16/2/17.
 */
public class MenuItem extends AnchorListItem {
    MenuItemModel model;
    public MenuItem(final MenuItemModel model){
        this.model = model;
        this.setText(model.getTitle());
        this.setIcon(model.icon());

        anchor.setHeight("30px");
        Style anchorStyle = anchor.getElement().getStyle();
        anchorStyle.setMarginTop(0, Style.Unit.PX);
        anchorStyle.setMarginBottom(0, Style.Unit.PX);

        anchorStyle.setPaddingTop(5, Style.Unit.PX);
        anchorStyle.setPaddingBottom(5, Style.Unit.PX);

        anchorStyle.setPaddingLeft(40, Style.Unit.PX);
        setHeight("30px");

        this.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                ActionEvent.fire(ActionEventBus.eventBus(),MenuItem.this,model);
            }
        });
    }
}
